﻿using System;
using System.Collections.Generic;
using System.Text;
using BarCode.Bean;
using BarCode.Common;
using System.Data;
using BarCode.Module;
using System.Data.OleDb;

namespace BarCode.AccessDao
{
    class RsBoxIdMdbDao
    {
        private static readonly log4net.ILog LogUtil = log4net.LogManager.GetLogger(typeof(RsBoxIdMdbDao));

        private AccessHelper rsboxidMdb;
        public RsBoxIdMdbDao()
        {
            rsboxidMdb = new AccessHelper(GlobalVal.ipAddressInfo.DISK_VALUE + Consts.MDB_RSBOXID);
        }

        public void Release()
        {
            rsboxidMdb.Release();
        }

        /// <summary>
        /// 获取批号信息
        /// </summary>
        /// <returns></returns>
        public string getBoxId()
        {

            DataSet retSet = rsboxidMdb.Query("select * from tblbaseid");
            if (retSet != null && retSet.Tables.Count > 0)
            {
                DataTable dt = retSet.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    return Convert.ToString(dt.Rows[0][0]);
                }
                else
                {
                   return "";
                }
            }
            else
            {
               return "";
            }

        }

        /// <summary>
        /// 设置批号信息
        /// </summary>
        /// <returns></returns>
        public int setBoxId(string boxId)
        {

            DataSet retSet = rsboxidMdb.Query("select * from tblbaseid");
            if (retSet != null && retSet.Tables.Count > 0)
            {
                DataTable dt = retSet.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    OleDbParameter[] sqlParams = new OleDbParameter[1];
                    sqlParams[0] = new OleDbParameter("boxid", boxId);
                    return rsboxidMdb.ExecuteSql("update tblbaseid set [baseid] = @boxid", sqlParams);
                }
                else
                {
                    OleDbParameter[] sqlParams = new OleDbParameter[1];
                    sqlParams[0] = new OleDbParameter("boxid", boxId);
                    return rsboxidMdb.ExecuteSql("insert into tblbaseid ([baseid]) values (@boxid)", sqlParams);
                }
            }
            else
            {
                OleDbParameter[] sqlParams = new OleDbParameter[1];
                sqlParams[0] = new OleDbParameter("boxid", boxId);
                return rsboxidMdb.ExecuteSql("insert into tblbaseid ([baseid]) values (@boxid)", sqlParams);
            }
        }

        /// <summary>
        /// 更新标志
        /// </summary>
        /// <param name="idSign"></param>
        /// <returns></returns>
        public int updateIdSign(string idSign)
        {
            OleDbParameter[] sqlParams = new OleDbParameter[1];
            sqlParams[0] = new OleDbParameter("idSign", idSign);
            return rsboxidMdb.ExecuteSql("update tblsign set [id_sign]= = @idSign", sqlParams);
        }
    }
}
